#ifndef _CREATURE_H
#define _CREATURE_H

class GossipScript;

class DLL_EXPORT Creature : public Unit
{
	friend class Player;
	ui32 _fields[UNIT_END];
	bool m_loaded;
	TaxiNode* m_taxinode;
	Trainer* m_trainer;
	WayPointEntry* m_waypoint;
	ui32 m_lastwaypoint;
	_WayPointEntry* frm, *tom;
	ui32 wpmin, wpmax;
	stdext::hash_map<ui32, _WayPointEntry*> m_waypoints;
	GuardPoi* m_guardpoi;
	void AddInRangeObject(Object* obj);
	_WayPointEntry* GetNextWaypoint();
	void WaypointCallback();
	Vector3d m_lastsrc, m_lastdest;
	ui32 m_lastmovement;
	ui32 m_timetodest;
	ui32 m_lastmoveupdate;
	CreatureAI m_creatureai;
	bool ismoving;
	bool m_wpsloaded;
	void UpdateMovements();
	void PlayerLoaded(Player* plr);
	void UnitGoneActive();
public:

	ui32 m_sqlid;
	Creature(ui64 guid);
	void OnPushToWorld();
	void Load(ui32 entry);
	void Spawn(float x, float y, float z, ui32 map, float o = 1.0f);
	void SaveToDb(bool first);
	void RemoveFromDb();
	GossipScript* m_gscript;
	CreatureScript* m_script;
	CreatureAI& GetCreatureAI() { return m_creatureai; }
	bool IsQuestGiver();
	bool IsGossipNpc();
	bool IsInnkeeper();
	bool IsBattlemaster();
	bool IsTrainer();
	bool IsTaxiVendor();
	bool IsGuard();
	bool HasFlag(ui32 flag);
	bool Update(ui32 time);
	
	Trainer* GetTrainer() { return m_trainer; }

	void RemoveFromWorld();

	void HandleInnRequest(Player* requester);
	void HandleInnSelection(Player* requester, ui32 id);
	void HandleTaxiRequest(Player* requester);
	void SendTaxiList(Player* requester);
	void HandleTrainerClick(Player* requester);
	void HandleTrainerBuy(Player* requester);
	// Same behaviour as SendSpellList but sends an empty trainer-list
	void SendNullSpell(Player* requester);
	// This has no effect if the client didnt had a gossipmenu before!
	// It will be sent but the client wont display it
	void SendSpellList(Player* requester);
	void HandleGuardHello(Player* requester);
	void HandleGuardSelect(Player* requester, ui32 id);

	ui32 MoveTo(float x, float y, float z, bool run = false);
	//	Stops the current movementaction
	void StopMovement();
	void StopWaypointing(ui32 time = 0);
	void RestartWaypointing();
};

#endif